package com.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.project.bean.ClassBean;
import com.project.bean.StudentBean;
import com.project.mapper.IClassMapper;
import com.project.mapper.IStudentMapper;
import com.project.service.IClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class ClassServiceImpl implements IClassService {

    @Autowired
    private IClassMapper mapper;

    @Autowired
    private IStudentMapper stuMapper;


    @Override
    public List<ClassBean> findAll() {
        return mapper.findAll();
    }

    @Override
    public boolean del(Integer id) {
        QueryWrapper<StudentBean> qw = new QueryWrapper<>();
        qw.eq("fk_classId",id);
        Integer num = stuMapper.selectCount(qw);
        if (num == 0 ){
             mapper.deleteById(id);
             return true;
        }

            return false;
    }



    @Override
    public void add(ClassBean classBean) {
        mapper.add(classBean);
    }
}
